home *** CD-ROM | disk | FTP | other *** search
/ Mastering Computers 3 / Mastering Computers Vol 3.iso / Win95 / Fun&Utils / MFCMSG.EXE / APPDOCS.CPP next >
Encoding:
C/C++ Source or Header  |  1995-07-01  |  1.0 KB  |  40 lines

  1. #include "stdafx.h"
  2. #include "appdocs.h"
  3.  
  4. /////////////////
  5. // Send WM_NOTIFY to all docs
  6. //
  7. BOOL CAppDocs::SendNotify(UINT nID, int nCode, NMHDR* pNMHDR)
  8. {
  9.    return SendCmdMsg(nID, MAKELONG(nCode, WM_NOTIFY), pNMHDR);
  10. }
  11.  
  12. //////////////////
  13. // Send command to all docs
  14. //
  15. BOOL CAppDocs::SendCommand(UINT nID)
  16. {
  17.    return SendCmdMsg(nID, CN_COMMAND, NULL);
  18. }
  19.  
  20. //////////////////
  21. // Private helper sends either command or notification
  22. // Loop for all docs and call doc->OnCmdMsg
  23. //
  24. BOOL CAppDocs::SendCmdMsg(UINT nID, int nCode, void* pExtra)
  25. {
  26.    BOOL bAnyHandled = FALSE;
  27.    CPtrList& tempList = AfxGetApp()->m_templateList;
  28.    POSITION pos1 = tempList.GetHeadPosition();
  29.    while (pos1) {
  30.       CDocTemplate* pTemplate=(CDocTemplate*)tempList.GetNext(pos1);
  31.       POSITION pos2 = pTemplate->GetFirstDocPosition();
  32.       while (pos2) {
  33.          CDocument *pDoc = pTemplate->GetNextDoc(pos2);
  34.          if (pDoc->OnCmdMsg(nID, nCode, pExtra, NULL))
  35.             bAnyHandled=TRUE;
  36.       }
  37.    }
  38.    return bAnyHandled;
  39. }
  40.